//headers 
#include<algorithm>
#include<cassert>
#include<cstdio>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<deque>
#include<set>
#include<string>
#include<sstream>
#include<stack>
#include<streambuf>
#include<vector>
using namespace std;

//macros
#define LET(x,a) typeof(a) x(a)
#define FOR(i,a,n) for(LET(i,a);i!=n;i++)
#define REP(i,n) FOR(i,0,n)
#define sz size()
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define dbge(x) cout<<#x<<"->"<<x<<endl;
#define PRINT(x) REP(_,x.sz) cout<<x[_]<<" "; cout<<endl;
#define OUT(x) x<<" "
const int INF = (int) 1e8;
#define VI vector<int>
#define VS vector<string>
#define VVI vector< vector<int> >
#define LL long long

//code of suren

map<string,int> vertex;
VVI graph;
VI seen;

int main(){
  int n;
  while( cin>>n , n ){
    vertex.clear();
    int t; cin>>t;
    int N=0;
    vertex["Rome"]=0;
    while(t--) {
      string i,j; cin>>i>>j;
      if( vertex.find(i)==vertex.end() ) vertex[i]=N++;
      if( vertex.find(j)==vertex.end() ) vertex[j]=N++;
    }
    
    
  }
}
